<template>
  <div class="warn-group">
    <set-group :col-set="colSet" ref="groupRef"></set-group>
  </div>
  <div class="btn-list flex-center">
    <BtnGroup close-name="还原" submit-name="保存" @close="getData" @submit="save"></BtnGroup>
  </div>
</template>

<script setup>
import {colSet} from "@/components/customs/dialog-set/component/base-set/data";
import {ref} from "@vue/reactivity";
import {onMounted} from "@vue/runtime-core";
import {JcszApi, JcszPostApi} from "@/common/customs/overview";
import BtnGroup from "@/components/customs/btn-group";
import {message} from "ant-design-vue";
import SetGroup from "@/components/customs/set-group/index.vue"

const timeData = ref({});
const groupRef = ref();

const getData = async () => {
  const api = new JcszApi();
  await api.send();
  const {data} = await api.getDatas();
  groupRef.value.timeData = {
    zc: [data[0].kqks, data[0].kqjs],
    cd: [data[0].cdks, data[0].cdjs],
    zcw: data[0].zcw
  };
};
const save = async () => {
  timeData.value = groupRef.value.timeData
  const api = new JcszPostApi();
  api.data({
    kqks: timeData.value.zc[0],
    kqjs: timeData.value.zc[1],
    cdks: timeData.value.cd[0],
    cdjs: timeData.value.cd[1],
    zcw: timeData.value.zcw,
  });
  await api.send();
  const {msg, code} = await api.getDatas();
  if (code === 0) {
    message.success("保存成功");
  } else {
    message.error(msg);
  }
};
onMounted(() => {
  getData();
});
</script>

<style lang="less" scoped>
@import "./index.less";
</style>
